package com.yl.order.ui.dialog;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.yl.common.ui.BaseDialogFragment;
import com.yl.order.R;
import com.yl.order.interfaces.Callback;

/**
 * create by cjx on 2024/5/16
 * desc: 确认对话框
 */
public class TipDialogFragment extends BaseDialogFragment implements View.OnClickListener {

    Callback<Integer> confirmCallback;
    TextView descView;
    private String title;
    private String subTitle;
    private String describe;

    public static TipDialogFragment newInstance() {
        return new TipDialogFragment();
    }

    @Override
    public int getViewId() {
        return R.layout.dialog_tip;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (!TextUtils.isEmpty(title)) {
            ((TextView) findViewById(R.id.title)).setText(title);
        }
        if (TextUtils.isEmpty(subTitle)) {
            findViewById(R.id.sub_title).setVisibility(View.GONE);
        } else {
            ((TextView) findViewById(R.id.sub_title)).setText(subTitle);
        }
        descView = findViewById(R.id.describe);
        descView.setText(describe);

        findViewById(R.id.confirm).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        dismiss();
        if (id == R.id.confirm) {
            if (confirmCallback != null) {
                confirmCallback.callback(0);
            }
        }
    }

    public TipDialogFragment setTitle(String title) {
        this.title = title;
        return this;
    }

    public TipDialogFragment setDescribe(String describe) {
        if (descView != null) {
            descView.setText(describe);
        }
        this.describe = describe;
        return this;
    }

    public TipDialogFragment setConfirmCallback(Callback<Integer> confirmCallback) {
        this.confirmCallback = confirmCallback;
        return this;
    }

    public TipDialogFragment setSubTitle(String subTitle) {
        this.subTitle = subTitle;
        return this;
    }
}
